/** ***************************************************************************
 * CoffeeZip.cpp
 * 2012 CoffeeParty Ltd.
 * Date Created: 2012-07-21                                  format YYYY-MM-DD
 * Revision Id: $Id$
 ******************************************************************************
 */
#ifndef _COFFEE_ZIP_HPP_
#define _COFFEE_ZIP_HPP_

#include "CoffeeCommons.hpp"
#include "CoffeeLogger.hpp"
#include "CoffeeIO.hpp"

#ifdef __USE_LONG_HEADER_PATH
# include "CoffeeMate/zlib/zlib.h"
#else
# include "zlib.h"
#endif

class CoffeeZip
{
protected:
    enum EI_GZIPFlags
    {
        GZ_TEXT_DAT  = 1,
        GZ_CRC16     = 2,
        GZ_EX_FIELDS = 4,
        GZ_FILENAME  = 8,
        GZ_COMMENT   = 16,
    };

    struct SI_GZIPHeader
    {
        unsigned short signature;      //!< 0x8b1f
        unsigned char compressMethod; //!< 8 = Deflate
        unsigned char flags;
        unsigned int time;
        unsigned char extraFlags;     //!< 2 = Slow, 4 = Fast
        unsigned char os;
    };

public:
    CoffeeZip();
    ~CoffeeZip();

    void testCompress();
    void testDeflate();
    void testInflate();

protected:
    bool open(const char *filename);
    void inflateStream(size_t offset, size_t uncompress_size, size_t compress_size, int compress_method);
    void checkError(int n, int line);

protected:
    CoffeeFile *qptr;
    SI_GZIPHeader header;
};

#endif /** _COFFEE_ZIP_HPP_ */
